package com.wwwarehouse.carddesk.fragment.teamfragment.checkupclassfragment;

import android.os.Bundle;

import com.alibaba.fastjson.JSON;
import com.wwwarehouse.carddesk.R;
import com.wwwarehouse.carddesk.bean.teambean.AllPowerDetailBean;
import com.wwwarehouse.carddesk.constant.CardDeskConstant;
import com.wwwarehouse.common.fragment.CommonBasePagerFragment;
import com.wwwarehouse.common.tools.LogUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @创建者 chenchao.
 * @创建时间 2017/11/13 17:22
 * @描述 ${TODO}
 */

public class AllPowerFragment extends CommonBasePagerFragment {

    private String mAuthorizeTeamUserId;
    private String mBeauthorizedTeamUserId;

    @Override
    public void setTitle() {
        if (peekFragment() instanceof AllPowerFragment) {
            mActivity.setTitle(R.string.teamdesk_all_power);
        }

    }

    @Override
    public void requestDatas() {
        super.requestDatas();
        hideConfirmButton();
        if (getArguments() != null) {
            mAuthorizeTeamUserId = getArguments().getString("authorizeTeamUserId");
            mBeauthorizedTeamUserId = getArguments().getString("beauthorizedTeamUserId");
        }
        requestHttp();


//        ArrayList list = new ArrayList();
//        for (int i = 0; i < 30; i++) {
//            AllPowerDetailBean allPowerDetailBean = new AllPowerDetailBean();
//            allPowerDetailBean.setPower("仓库权限》入库权限");
//            allPowerDetailBean.setCompanyName("浙江我那个沧海科技有相");
//            allPowerDetailBean.setStartTime("2017-09-15 16:00");
//            allPowerDetailBean.setEndTime("2017-29-71 15:52");
//            list.add(allPowerDetailBean);
//        }
//        try {
//            setData(30, 7, "com.wwwarehouse.carddesk.fragment.teamfragment.checkupclassfragment.AllPowerFragmentChild", null, list);
//        } catch (Exception e) {
//            LogUtils.showLog(e.toString());
//        }
    }

    private void requestHttp() {
        Map<String, Object> powerMap = new HashMap<>();
        powerMap.put("authorityCode", 3);
        powerMap.put("authorizeTeamUserId", mAuthorizeTeamUserId);
        powerMap.put("beauthorizedTeamUserId", mBeauthorizedTeamUserId);
        powerMap.put("page", 1);
        powerMap.put("size", 7);
        loadData(CardDeskConstant.GET_RELATIONAUITEM_INFO, powerMap, 0);
    }

    @Override
    public void onRefreshListener() {
        requestHttp();
    }

    @Override
    public void onLoadSuccess(String data, int what) {
        if (0 == what) {
            AllPowerDetailBean allPowerDetailBean = JSON.parseObject(data, AllPowerDetailBean.class);
            int total = allPowerDetailBean.getTotal();
            ArrayList<AllPowerDetailBean.ListBean> list = (ArrayList<AllPowerDetailBean.ListBean>)allPowerDetailBean.getList();
            Bundle powerToChildBundle = new Bundle();
            powerToChildBundle.putString("authorizeTeamUserId", mAuthorizeTeamUserId);
            powerToChildBundle.putString("beauthorizedTeamUserId", mBeauthorizedTeamUserId);
            try {
                setData(total, 7, "com.wwwarehouse.carddesk.fragment.teamfragment.checkupclassfragment.AllPowerFragmentChild", powerToChildBundle, list);
            } catch (Exception e) {
                LogUtils.showLog(e.toString());
            }

        }
    }

    @Override
    public void onLoadError(String errorInfo) {

    }

    @Override
    public void onDownPull() {
        //        super.onDownPull();
    }
}
